package Beans;

import BLL.BranchBLL;
import Entities.TblBranch;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author CuongNV
 */
@ManagedBean
@SessionScoped
public class BranchManagedBean extends TblBranch implements Serializable {

    //Gen code set get trước rồi thêm static vào!
    private static TblBranch branchSelected;

    /** Creates a new instance of BranchManagedBean */
    public BranchManagedBean() {        
    }

    public String add() throws Exception {
        boolean check = new BLL.BranchBLL().add(this);
        if (check) {
            return "branchList";
        } else {
            return null;
        }
    }

    public String update() throws Exception {
        boolean check = new BLL.BranchBLL().update(branchSelected);
        if (check) {
            return "branchList";
        } else {
            return null;
        }
    }

    public String delete() throws Exception{
        boolean check = new BLL.BranchBLL().delete(branchSelected);
        if (check) {
            return "branchList";
        } else {
            return null;
        }
    }

    public List<TblBranch> getAll() throws Exception {
        return new BranchBLL().getAll();
    }

    public TblBranch getBranchSelected() {
        return branchSelected;
    }

    public void setBranchSelected(TblBranch branchSelected) {
        BranchManagedBean.branchSelected = branchSelected;
    }
}
